/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FichaPodologa.java
 *
 * Created on 16-10-2012, 02:52:13 PM
 */
package SubsistemaPaciente.Fichas;

import clienteSandraParada.Login;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Color;
import java.awt.Desktop;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Jacqueline
 */
public class FichaPodologa extends javax.swing.JDialog {

    Long id;
    int fila;
    static public Long FichaFiltrar;
    String profesional = Login.getUser().getRut();
    PanelPodologia p;
    boolean calzadoAdecuado, problemaOrto, caminaAyuda, diabetesM, hta, ulceracion,
            amputacion, alergias, varices, enfermedadesCro;

    /** Creates new form FichaPodologa */
    public FichaPodologa(java.awt.Frame parent, boolean modal, PanelPodologia p) {
        super(parent, modal);
        initComponents();
        setIconImage(new ImageIcon(getClass().getResource("/GUI/Img/logo2.png")).getImage());
        this.p = p;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel23 = new javax.swing.JPanel();
        accion2 = new javax.swing.JButton();
        cancelar2 = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        nombres2 = new javax.swing.JTextField();
        apellidoPaterno2 = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        rut3 = new componentes.Rut();
        apellidoMaterno2 = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        prevision2 = new javax.swing.JTextField();
        jLabel31 = new javax.swing.JLabel();
        telefono3 = new componentes.Telefono();
        fechaNacimiento2 = new javax.swing.JTextField();
        jLabel63 = new javax.swing.JLabel();
        jLabel64 = new javax.swing.JLabel();
        profesion2 = new javax.swing.JTextField();
        jPanel21 = new javax.swing.JPanel();
        jLabel65 = new javax.swing.JLabel();
        jLabel66 = new javax.swing.JLabel();
        jLabel67 = new javax.swing.JLabel();
        jLabel68 = new javax.swing.JLabel();
        jLabel69 = new javax.swing.JLabel();
        jLabel70 = new javax.swing.JLabel();
        jLabel71 = new javax.swing.JLabel();
        jLabel72 = new javax.swing.JLabel();
        jLabel73 = new javax.swing.JLabel();
        jLabel74 = new javax.swing.JLabel();
        jLabel75 = new javax.swing.JLabel();
        jLabel76 = new javax.swing.JLabel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jRadioButton8 = new javax.swing.JRadioButton();
        jRadioButton9 = new javax.swing.JRadioButton();
        jRadioButton10 = new javax.swing.JRadioButton();
        jLabel77 = new javax.swing.JLabel();
        jLabel78 = new javax.swing.JLabel();
        jRadioButton11 = new javax.swing.JRadioButton();
        jRadioButton12 = new javax.swing.JRadioButton();
        jRadioButton13 = new javax.swing.JRadioButton();
        jRadioButton14 = new javax.swing.JRadioButton();
        jRadioButton15 = new javax.swing.JRadioButton();
        jRadioButton16 = new javax.swing.JRadioButton();
        jRadioButton17 = new javax.swing.JRadioButton();
        jRadioButton18 = new javax.swing.JRadioButton();
        jRadioButton19 = new javax.swing.JRadioButton();
        jRadioButton20 = new javax.swing.JRadioButton();
        jLabel79 = new javax.swing.JLabel();
        jLabel80 = new javax.swing.JLabel();
        medicamentos = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        cal = new javax.swing.JSpinner();
        cal2 = new javax.swing.JSpinner();
        jPanel22 = new javax.swing.JPanel();
        jScrollPane11 = new javax.swing.JScrollPane();
        tablaAsistencia2 = new javax.swing.JTable();
        agregarEvolucion2 = new javax.swing.JButton();
        modificarvolucion2 = new javax.swing.JButton();
        jLabel81 = new javax.swing.JLabel();
        desdeEvo2 = new com.toedter.calendar.JDateChooser();
        jLabel82 = new javax.swing.JLabel();
        hastaEvo2 = new com.toedter.calendar.JDateChooser();
        verEvolucion = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        mensajeriaFormulario = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel23.setMaximumSize(new java.awt.Dimension(1085, 450));
        jPanel23.setMinimumSize(new java.awt.Dimension(1085, 450));
        jPanel23.setPreferredSize(new java.awt.Dimension(1085, 450));

        accion2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png"))); // NOI18N
        accion2.setText("Guardar");
        accion2.setToolTipText("Guardar");
        accion2.setAlignmentY(0.0F);
        accion2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                accion2ActionPerformed(evt);
            }
        });

        cancelar2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Cancelar.png"))); // NOI18N
        cancelar2.setText("Cancelar");
        cancelar2.setToolTipText("Eliminar");
        cancelar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelar2ActionPerformed(evt);
            }
        });

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos personales"));

        jLabel24.setText("Rut:");

        jLabel25.setText("Nombres:");

        jLabel26.setText("Apellido paterno:");

        nombres2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombres2ActionPerformed(evt);
            }
        });

        jLabel29.setText("Apellido materno:");

        jLabel30.setText("Previsión");

        jLabel31.setText("Teléfono:");

        jLabel63.setText("Fecha nacimiento:");

        jLabel64.setText("Profesión:");

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel29)
                    .addComponent(jLabel24)
                    .addComponent(jLabel26)
                    .addComponent(jLabel25)
                    .addComponent(jLabel30)
                    .addComponent(jLabel63))
                .addGap(46, 46, 46)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nombres2, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rut3, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(apellidoPaterno2, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(apellidoMaterno2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel10Layout.createSequentialGroup()
                                .addComponent(fechaNacimiento2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(38, 38, 38))
                            .addGroup(jPanel10Layout.createSequentialGroup()
                                .addComponent(prevision2)
                                .addGap(24, 24, 24)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 89, Short.MAX_VALUE)
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel31, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel64))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(telefono3, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(profesion2, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jLabel24)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel25)
                .addGap(13, 13, 13)
                .addComponent(jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel29)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel30)
                .addGap(38, 38, 38))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(rut3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nombres2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addComponent(apellidoPaterno2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(apellidoMaterno2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(prevision2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fechaNacimiento2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel63)))
                    .addGroup(jPanel10Layout.createSequentialGroup()
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(telefono3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel31))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(profesion2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel64))))
                .addContainerGap())
        );

        jPanel21.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos clínicos"));

        jLabel65.setText("Calzado adecuado:");

        jLabel66.setText("Problemas ortopédicos:");

        jLabel67.setText("Camina con ayuda:");

        jLabel68.setText("H.T.A:");

        jLabel69.setText("Diabetes mellitus:");

        jLabel70.setText("Amputación previa:");

        jLabel71.setText("Ulceración previa:");

        jLabel72.setText("Alergias:");

        jLabel73.setText("Varices:");

        jLabel74.setText("  Si");

        jLabel75.setText("No");

        jLabel76.setText("Enfermedades crónicas:");

        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton4ActionPerformed(evt);
            }
        });

        jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton5ActionPerformed(evt);
            }
        });

        jRadioButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton6ActionPerformed(evt);
            }
        });

        jRadioButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton7ActionPerformed(evt);
            }
        });

        jRadioButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton8ActionPerformed(evt);
            }
        });

        jRadioButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton9ActionPerformed(evt);
            }
        });

        jRadioButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton10ActionPerformed(evt);
            }
        });

        jLabel77.setText("  Si");

        jLabel78.setText("No");

        jRadioButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton11ActionPerformed(evt);
            }
        });

        jRadioButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton12ActionPerformed(evt);
            }
        });

        jRadioButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton13ActionPerformed(evt);
            }
        });

        jRadioButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton14ActionPerformed(evt);
            }
        });

        jRadioButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton15ActionPerformed(evt);
            }
        });

        jRadioButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton16ActionPerformed(evt);
            }
        });

        jRadioButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton17ActionPerformed(evt);
            }
        });

        jRadioButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton18ActionPerformed(evt);
            }
        });

        jRadioButton19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton19ActionPerformed(evt);
            }
        });

        jRadioButton20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton20ActionPerformed(evt);
            }
        });

        jLabel79.setText("N° calzado:");

        jLabel80.setText("Medicamentos:");

        jLabel4.setText("* ");

        jLabel5.setText("*");

        javax.swing.GroupLayout jPanel21Layout = new javax.swing.GroupLayout(jPanel21);
        jPanel21.setLayout(jPanel21Layout);
        jPanel21Layout.setHorizontalGroup(
            jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel21Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel69)
                    .addGroup(jPanel21Layout.createSequentialGroup()
                        .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel65)
                            .addComponent(jLabel66)
                            .addComponent(jLabel79))
                        .addGap(47, 47, 47)
                        .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel21Layout.createSequentialGroup()
                                .addComponent(cal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cal2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel21Layout.createSequentialGroup()
                                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton10)
                                    .addComponent(jRadioButton6)
                                    .addComponent(jRadioButton2)
                                    .addComponent(jRadioButton4)
                                    .addComponent(jRadioButton8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                                    .addComponent(jRadioButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                                    .addComponent(jRadioButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                                    .addComponent(jRadioButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                                    .addComponent(jRadioButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)))
                            .addGroup(jPanel21Layout.createSequentialGroup()
                                .addComponent(jLabel74)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel75))))
                    .addComponent(jLabel67)
                    .addComponent(jLabel68))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addGap(62, 62, 62)
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel76)
                    .addComponent(jLabel73)
                    .addComponent(jLabel72)
                    .addComponent(jLabel70)
                    .addComponent(jLabel71)
                    .addComponent(jLabel80))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel21Layout.createSequentialGroup()
                        .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel21Layout.createSequentialGroup()
                                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jRadioButton13, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton11, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton15)
                                    .addComponent(jRadioButton16)
                                    .addComponent(jRadioButton17))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton12)
                                    .addComponent(jRadioButton14)
                                    .addComponent(jRadioButton20)
                                    .addComponent(jRadioButton19)
                                    .addComponent(jRadioButton18)))
                            .addGroup(jPanel21Layout.createSequentialGroup()
                                .addComponent(jLabel77)
                                .addGap(14, 14, 14)
                                .addComponent(jLabel78)))
                        .addGap(16, 16, 16))
                    .addComponent(medicamentos, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addContainerGap())
        );
        jPanel21Layout.setVerticalGroup(
            jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel21Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel21Layout.createSequentialGroup()
                            .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel78)
                                .addComponent(jLabel77))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton12)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton14)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton20)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton19)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton18))
                        .addGroup(jPanel21Layout.createSequentialGroup()
                            .addGap(16, 16, 16)
                            .addComponent(jRadioButton11)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton13)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton15)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton16)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton17)))
                    .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel21Layout.createSequentialGroup()
                            .addGap(16, 16, 16)
                            .addComponent(jRadioButton10)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton6)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jRadioButton8))
                        .addGroup(jPanel21Layout.createSequentialGroup()
                            .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel74)
                                .addComponent(jLabel75))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                .addComponent(jLabel65)
                                .addComponent(jRadioButton9)
                                .addComponent(jLabel71))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                .addComponent(jLabel66)
                                .addComponent(jRadioButton5)
                                .addComponent(jLabel70))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                .addComponent(jLabel67)
                                .addComponent(jRadioButton1)
                                .addComponent(jLabel72))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                .addComponent(jLabel69)
                                .addComponent(jRadioButton3)
                                .addComponent(jLabel73))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                .addComponent(jLabel68)
                                .addComponent(jRadioButton7)
                                .addComponent(jLabel76)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(medicamentos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel80)
                        .addComponent(jLabel5))
                    .addGroup(jPanel21Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel79)
                        .addComponent(jLabel4)
                        .addComponent(cal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cal2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel22.setBorder(javax.swing.BorderFactory.createTitledBorder("Atenciones realizadas"));

        tablaAsistencia2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Sesión", "Fecha", "Evolución"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane11.setViewportView(tablaAsistencia2);

        agregarEvolucion2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png"))); // NOI18N
        agregarEvolucion2.setToolTipText("Agregar evolución");
        agregarEvolucion2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregarEvolucion2ActionPerformed(evt);
            }
        });

        modificarvolucion2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Edit2.png"))); // NOI18N
        modificarvolucion2.setToolTipText("Modificar evolución");
        modificarvolucion2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificarvolucion2ActionPerformed(evt);
            }
        });

        jLabel81.setText("Desde:");

        desdeEvo2.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                desdeEvo2PropertyChange(evt);
            }
        });

        jLabel82.setText("Hasta:");

        hastaEvo2.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                hastaEvo2PropertyChange(evt);
            }
        });

        verEvolucion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Previsualizar.png"))); // NOI18N
        verEvolucion.setToolTipText("Ver evolución");
        verEvolucion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verEvolucionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel22Layout = new javax.swing.GroupLayout(jPanel22);
        jPanel22.setLayout(jPanel22Layout);
        jPanel22Layout.setHorizontalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel22Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel22Layout.createSequentialGroup()
                        .addComponent(jScrollPane11, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(agregarEvolucion2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(modificarvolucion2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(verEvolucion)))
                    .addGroup(jPanel22Layout.createSequentialGroup()
                        .addComponent(jLabel81)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(desdeEvo2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel82)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(hastaEvo2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel22Layout.setVerticalGroup(
            jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel22Layout.createSequentialGroup()
                .addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel22Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addGroup(jPanel22Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel81)
                            .addComponent(jLabel82)
                            .addComponent(desdeEvo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(hastaEvo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addGroup(jPanel22Layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addComponent(agregarEvolucion2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(modificarvolucion2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(verEvolucion)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jLabel6.setText("* Datos obligatorios");

        mensajeriaFormulario.setText("Área de mensajería");

        javax.swing.GroupLayout jPanel23Layout = new javax.swing.GroupLayout(jPanel23);
        jPanel23.setLayout(jPanel23Layout);
        jPanel23Layout.setHorizontalGroup(
            jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel23Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel23Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(accion2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelar2))
                    .addGroup(jPanel23Layout.createSequentialGroup()
                        .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel22, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(14, 14, 14))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel23Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(mensajeriaFormulario, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(354, 354, 354))
        );
        jPanel23Layout.setVerticalGroup(
            jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel23Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel23Layout.createSequentialGroup()
                        .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanel21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel22, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel23Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel23Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cancelar2)
                            .addComponent(accion2)))
                    .addGroup(jPanel23Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jLabel6)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mensajeriaFormulario)
                .addGap(20, 20, 20))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel23, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel23, javax.swing.GroupLayout.PREFERRED_SIZE, 477, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void hastaEvo2PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_hastaEvo2PropertyChange
        // TODO add your handling code here:
        if (this.desdeEvo2.getDate() != null && this.hastaEvo2.getDate() != null) {
            this.actualizarTablaFiltro();
        }
}//GEN-LAST:event_hastaEvo2PropertyChange

    private void desdeEvo2PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_desdeEvo2PropertyChange
        // TODO add your handling code here:
        if (this.desdeEvo2.getDate() != null && this.hastaEvo2.getDate() != null) {
            this.actualizarTablaFiltro();
        }
}//GEN-LAST:event_desdeEvo2PropertyChange

    private void modificarvolucion2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificarvolucion2ActionPerformed
        // modificar Evolucion podologa
        this.mensajeriaFormulario.setText("");
        Evolucion evo = new Evolucion(null, true, this);
        evo.setTitle("Modificar Evolucion");
        evo.configurarBotones("modificar");
        int[] filasSelec = tablaAsistencia2.getSelectedRows();
        if (filasSelec.length == 1) { //ha seleccionado una fila de la tabla
            int fil = filasSelec[0];
            service.Evolucion evoAModificar = buscarEvolucionAModificar((Integer) tablaAsistencia2.getValueAt(fil, 0),
                    (String) tablaAsistencia2.getValueAt(fil, 1), (String) tablaAsistencia2.getValueAt(fil, 2));
            Evolucion.idEvolucion = evoAModificar.getId();
            Evolucion.idFichaEvo = evoAModificar.getFichaClinica();
            evo.llenarDatosFormularioEvolucion(evoAModificar);
            evo.habilitarCamposFormulario(true);
            evo.ocultarCamposObligatorios(false);
            evo.setLocationRelativeTo(null);
            evo.setVisible(true);
        } else {
            this.mensajeriaFormulario.setText("Debe seleccionar una evolución");
            this.mensajeriaFormulario.setForeground(Color.red);
        }
}//GEN-LAST:event_modificarvolucion2ActionPerformed

    public service.Evolucion buscarEvolucionAModificar(int sesion, String fecha, String comentario) {
        service.EvolucionWSService service = new service.EvolucionWSService();
        service.EvolucionWS port = service.getEvolucionWSPort();

        java.util.List<service.Evolucion> evoluciones = port.listarEvoluciones();
        //buscar la ficha clinica por el id de la ficha
        for (int i = 0; i < evoluciones.size(); i++) {
            if (evoluciones.get(i).getSesion() == sesion && evoluciones.get(i).getFecha().equals(fecha)
                    && evoluciones.get(i).getComentario().equals(comentario)) {
                return evoluciones.get(i);
            }
        }
        return null;
    }

    private void agregarEvolucion2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregarEvolucion2ActionPerformed
        // agregarEvolucion ficha podologa
        this.mensajeriaFormulario.setText("");
        Evolucion evo = new Evolucion(null, true, this);
        evo.setTitle("Agregar Evolucion");
        evo.configurarBotones("agregar");
        evo.limpiarFormularioEvolucion();

        int sesion=calcularNumeroSesion(Evolucion.ficha);
        evo.agregarDatos(Integer.toString(sesion));
        evo.setLocationRelativeTo(null);
        evo.setVisible(true);
}//GEN-LAST:event_agregarEvolucion2ActionPerformed

    public int calcularNumeroSesion(Long ficha) {
        int numeroSesiones = 0;

        service.EvolucionWSService service = new service.EvolucionWSService();
        service.EvolucionWS port = service.getEvolucionWSPort();

        java.util.List<service.Evolucion> evoluciones = port.listarEvoluciones();
        //buscar la ficha clinica por el id de la ficha
        for (int i = 0; i < evoluciones.size(); i++) {
            if (evoluciones.get(i).getFichaClinica().equals(ficha)) {
                numeroSesiones++;
            }
        }
        if (numeroSesiones == 0) {
            return 1;
        } else {
            return numeroSesiones + 1;
        }
    }

    private void jRadioButton20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton20ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton15.isSelected() == true) {
            this.jRadioButton15.setSelected(false);
            this.jRadioButton20.setSelected(true);
        } else {
            this.jRadioButton20.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton20ActionPerformed

    private void jRadioButton19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton19ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton16.isSelected() == true) {
            this.jRadioButton16.setSelected(false);
            this.jRadioButton19.setSelected(true);
        } else {
            this.jRadioButton19.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton19ActionPerformed

    private void jRadioButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton18ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton17.isSelected() == true) {
            this.jRadioButton17.setSelected(false);
            this.jRadioButton18.setSelected(true);
        } else {
            this.jRadioButton18.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton18ActionPerformed

    private void jRadioButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton17ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton18.isSelected() == true) {
            this.jRadioButton18.setSelected(false);
            this.jRadioButton17.setSelected(true);
        } else {
            this.jRadioButton17.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton17ActionPerformed

    private void jRadioButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton16ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton19.isSelected() == true) {
            this.jRadioButton19.setSelected(false);
            this.jRadioButton16.setSelected(true);
        } else {
            this.jRadioButton16.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton16ActionPerformed

    private void jRadioButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton15ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton20.isSelected() == true) {
            this.jRadioButton20.setSelected(false);
            this.jRadioButton15.setSelected(true);
        } else {
            this.jRadioButton15.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton15ActionPerformed

    private void jRadioButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton14ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton13.isSelected() == true) {
            this.jRadioButton13.setSelected(false);
            this.jRadioButton14.setSelected(true);
        } else {
            this.jRadioButton14.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton14ActionPerformed

    private void jRadioButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton13ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton14.isSelected() == true) {
            this.jRadioButton14.setSelected(false);
            this.jRadioButton13.setSelected(true);
        } else {
            this.jRadioButton13.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton13ActionPerformed

    private void jRadioButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton12ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton11.isSelected() == true) {
            this.jRadioButton11.setSelected(false);
            this.jRadioButton12.setSelected(true);
        } else {
            this.jRadioButton12.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton12ActionPerformed

    private void jRadioButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton11ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton12.isSelected() == true) {
            this.jRadioButton12.setSelected(false);
            this.jRadioButton11.setSelected(true);
        } else {
            this.jRadioButton11.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton11ActionPerformed

    private void jRadioButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton10ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton9.isSelected() == true) {
            this.jRadioButton9.setSelected(false);
            this.jRadioButton10.setSelected(true);
        } else {
            this.jRadioButton10.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton10ActionPerformed

    private void jRadioButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton9ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton10.isSelected() == true) {
            this.jRadioButton10.setSelected(false);
            this.jRadioButton9.setSelected(true);
        } else {
            this.jRadioButton9.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton9ActionPerformed

    private void jRadioButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton8ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton7.isSelected() == true) {
            this.jRadioButton7.setSelected(false);
            this.jRadioButton8.setSelected(true);
        } else {
            this.jRadioButton8.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton8ActionPerformed

    private void jRadioButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton7ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton8.isSelected() == true) {
            this.jRadioButton8.setSelected(false);
            this.jRadioButton7.setSelected(true);
        } else {
            this.jRadioButton7.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton7ActionPerformed

    private void jRadioButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton6ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton5.isSelected() == true) {
            this.jRadioButton5.setSelected(false);
            this.jRadioButton6.setSelected(true);
        } else {
            this.jRadioButton6.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton6ActionPerformed

    private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton5ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton6.isSelected() == true) {
            this.jRadioButton6.setSelected(false);
            this.jRadioButton5.setSelected(true);
        } else {
            this.jRadioButton5.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton5ActionPerformed

    private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton4ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton3.isSelected() == true) {
            this.jRadioButton3.setSelected(false);
            this.jRadioButton4.setSelected(true);
        } else {
            this.jRadioButton4.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton4ActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton4.isSelected() == true) {
            this.jRadioButton4.setSelected(false);
            this.jRadioButton3.setSelected(true);
        } else {
            this.jRadioButton3.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton3ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton1.isSelected() == true) {
            this.jRadioButton1.setSelected(false);
            this.jRadioButton2.setSelected(true);
        } else {
            this.jRadioButton2.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
        // TODO add your handling code here:
        if (this.jRadioButton2.isSelected() == true) {
            this.jRadioButton2.setSelected(false);
            this.jRadioButton1.setSelected(true);
        } else {
            this.jRadioButton1.setSelected(true);
        }
}//GEN-LAST:event_jRadioButton1ActionPerformed

    private void nombres2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nombres2ActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_nombres2ActionPerformed

    private void cancelar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelar2ActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_cancelar2ActionPerformed

    private void accion2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_accion2ActionPerformed
        // Accion a realizar con el formulario de Podologa
        valoresBooleanosFicha();
        //Acciones a realizar segun opción elegida.
        boolean duplicada = false;
        if (this.getTitle().equals("Agregar Ficha Podologia")) {
            duplicada = estaDuplicada(rut3.getRut().getText(), Login.getUser().getRut());
            boolean datosObligatorios = llenoDatosObligatorios();

            if(duplicada==false && datosObligatorios==true){
                String numCal= calcularNumeroCalzado();
                Long idFicha= p.agregarFichaPodologaBD(rut3.getRut().getText(),profesional,calzadoAdecuado,
                    problemaOrto,caminaAyuda,diabetesM,hta,ulceracion,amputacion,alergias,varices,
                    enfermedadesCro,numCal,medicamentos.getText(),true);
                service.FichaPodologa f = buscarFicha(idFicha);
                String valorNuevo = "Rut profesional: " + f.getProfesional() + "\n" + "Rut paciente: " + f.getPaciente() + "\n" + "Medicamentos: " + f.getMedicamentos() + "\n" + "Número calzado: " + f.getNumeroCalzado();
                registrar(Login.getUser(),"Ficha podología", "Agregó ficha podología a profesional:" + f.getProfesional() + "de paciente :" + f.getPaciente(), "No aplica", valorNuevo);
                p.etiquetaMensajeria.setText("La Ficha se ha agregado exitosamente");
                p.cargarFichas((java.util.List<service.FichaPodologa>) listarFichas());
            } else if (duplicada == true) {
                this.mensajeriaFormulario.setText("La ficha ya se encuentra en el sistema");
                this.mensajeriaFormulario.setForeground(Color.red);
            } else if (datosObligatorios == false) {
                this.mensajeriaFormulario.setText("Complete los campos obligatorios");
                this.mensajeriaFormulario.setForeground(Color.red);
            }
            if (duplicada == false && datosObligatorios == true) {
                this.dispose();
            }
        }
        else if(this.getTitle().equals("Modificar Ficha Podologia")){
            service.FichaPodologa f = buscarFicha(id);
            String valorAnterior = "Rut profesional: " + f.getProfesional() + "\n" + "Rut paciente: " + f.getPaciente() + "\n" + "Medicamentos: " + f.getMedicamentos() + "\n" + "Número calzado: " + f.getNumeroCalzado();
            String numCal= calcularNumeroCalzado();
            p.modificarFichaPodoBD(id,rut3.getRut().getText(),profesional,calzadoAdecuado,
                problemaOrto,caminaAyuda,diabetesM,hta,ulceracion,amputacion,alergias,varices,
                enfermedadesCro,numCal,medicamentos.getText(),true);
            p.cargarFichas((java.util.List<service.FichaPodologa>) listarFichas());
            f = buscarFicha(id);
            String valorNuevo = "Rut profesional: " + f.getProfesional() + "\n" + "Rut paciente: " + f.getPaciente() + "\n" + "Medicamentos: " + f.getMedicamentos() + "\n" + "Número calzado: " + f.getNumeroCalzado();
            registrar(Login.getUser(),"Ficha podología", "Modificó ficha podología a profesional:" + f.getProfesional() + "de paciente :" + f.getPaciente(), valorAnterior, valorNuevo);
            p.etiquetaMensajeria.setText("La Ficha se ha modificado exitosamente");
            this.dispose();
        } else if (this.getTitle().equals("Ver Ficha Podologia")) {
            try {
                this.dispose();
                service.FichaPodologa fichak = this.buscarFicha(id);
                imprimirFichaClinica(fichak);
            } catch (FileNotFoundException ex) {
                Logger.getLogger(FichaPodologa.class.getName()).log(Level.SEVERE, null, ex);
            } catch (DocumentException ex) {
                Logger.getLogger(FichaPodologa.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
}//GEN-LAST:event_accion2ActionPerformed

    private void verEvolucionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verEvolucionActionPerformed
        //ver Evolucion
        this.mensajeriaFormulario.setText("");
        Evolucion evo = new Evolucion(null, true, this);
        evo.setTitle("Ver Evolucion");
        evo.configurarBotones("ver");
        int[] filasSelec = tablaAsistencia2.getSelectedRows();
        if (filasSelec.length == 1) { //ha seleccionado una fila de la tabla
            int fil = filasSelec[0];
            service.Evolucion evoAModificar = buscarEvolucionAModificar((Integer) tablaAsistencia2.getValueAt(fil, 0),
                    (String) tablaAsistencia2.getValueAt(fil, 1), (String) tablaAsistencia2.getValueAt(fil, 2));
            Evolucion.idEvolucion = evoAModificar.getId();
            Evolucion.idFichaEvo = evoAModificar.getFichaClinica();
            evo.llenarDatosFormularioEvolucion(evoAModificar);
            evo.habilitarCamposFormulario(false);
            evo.ocultarCamposObligatorios(true);
            evo.setLocationRelativeTo(null);
            evo.setVisible(true);
        } else {
            this.mensajeriaFormulario.setText("Debe seleccionar una evolución");
            this.mensajeriaFormulario.setForeground(Color.red);
        }
    }//GEN-LAST:event_verEvolucionActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton accion2;
    private javax.swing.JButton agregarEvolucion2;
    private javax.swing.JTextField apellidoMaterno2;
    private javax.swing.JTextField apellidoPaterno2;
    private javax.swing.JSpinner cal;
    private javax.swing.JSpinner cal2;
    public javax.swing.JButton cancelar2;
    private com.toedter.calendar.JDateChooser desdeEvo2;
    private javax.swing.JTextField fechaNacimiento2;
    private com.toedter.calendar.JDateChooser hastaEvo2;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel63;
    private javax.swing.JLabel jLabel64;
    private javax.swing.JLabel jLabel65;
    private javax.swing.JLabel jLabel66;
    private javax.swing.JLabel jLabel67;
    private javax.swing.JLabel jLabel68;
    private javax.swing.JLabel jLabel69;
    private javax.swing.JLabel jLabel70;
    private javax.swing.JLabel jLabel71;
    private javax.swing.JLabel jLabel72;
    private javax.swing.JLabel jLabel73;
    private javax.swing.JLabel jLabel74;
    private javax.swing.JLabel jLabel75;
    private javax.swing.JLabel jLabel76;
    private javax.swing.JLabel jLabel77;
    private javax.swing.JLabel jLabel78;
    private javax.swing.JLabel jLabel79;
    private javax.swing.JLabel jLabel80;
    private javax.swing.JLabel jLabel81;
    private javax.swing.JLabel jLabel82;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel22;
    private javax.swing.JPanel jPanel23;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton10;
    private javax.swing.JRadioButton jRadioButton11;
    private javax.swing.JRadioButton jRadioButton12;
    private javax.swing.JRadioButton jRadioButton13;
    private javax.swing.JRadioButton jRadioButton14;
    private javax.swing.JRadioButton jRadioButton15;
    private javax.swing.JRadioButton jRadioButton16;
    private javax.swing.JRadioButton jRadioButton17;
    private javax.swing.JRadioButton jRadioButton18;
    private javax.swing.JRadioButton jRadioButton19;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton20;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JRadioButton jRadioButton8;
    private javax.swing.JRadioButton jRadioButton9;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JTextField medicamentos;
    public javax.swing.JLabel mensajeriaFormulario;
    private javax.swing.JButton modificarvolucion2;
    private javax.swing.JTextField nombres2;
    private javax.swing.JTextField prevision2;
    private javax.swing.JTextField profesion2;
    private componentes.Rut rut3;
    private javax.swing.JTable tablaAsistencia2;
    private componentes.Telefono telefono3;
    private javax.swing.JButton verEvolucion;
    // End of variables declaration//GEN-END:variables


    public String calcularNumeroCalzado(){
        String calza1= cal.getValue().toString();
        String calza2= cal2.getValue().toString();
        String calzadoNum=calza1+calza2;
        return calzadoNum;
    }

    public void configurarBotones(String formulario){
        if(formulario.equals("agregar")){

            this.accion2.setText("Aceptar");
            this.accion2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png")));
        } else if (formulario.equals("modificar")) {
            this.accion2.setText("Guardar");
            this.accion2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png")));
        } else {
            this.accion2.setText("Exportar");
            this.accion2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/pdf.png")));
        }
    }

    public void limpiarFormularioPodo() {
        //datos personales
        this.rut3.getRut().setText("");
        this.nombres2.setText("");
        this.apellidoPaterno2.setText("");
        this.apellidoMaterno2.setText("");
        this.prevision2.setText("");
        this.telefono3.getTelefono().setText("");
        this.profesion2.setText("");
        this.fechaNacimiento2.setText("");
        //Datos Clinicos
        this.jRadioButton1.setSelected(false);
        this.jRadioButton2.setSelected(false);
        this.jRadioButton3.setSelected(false);
        this.jRadioButton4.setSelected(false);
        this.jRadioButton5.setSelected(false);
        this.jRadioButton6.setSelected(false);
        this.jRadioButton7.setSelected(false);
        this.jRadioButton8.setSelected(false);
        this.jRadioButton9.setSelected(false);
        this.jRadioButton10.setSelected(false);
        this.jRadioButton11.setSelected(false);
        this.jRadioButton12.setSelected(false);
        this.jRadioButton13.setSelected(false);
        this.jRadioButton14.setSelected(false);
        this.jRadioButton15.setSelected(false);
        this.jRadioButton16.setSelected(false);
        this.jRadioButton17.setSelected(false);
        this.jRadioButton18.setSelected(false);
        this.jRadioButton19.setSelected(false);
        this.jRadioButton20.setSelected(false);
    }

    public void llenarFormularioPodologa(service.Paciente pac) {
        this.rut3.getRut().setText(pac.getRut());
        this.nombres2.setText(pac.getNombres());
        this.apellidoPaterno2.setText(pac.getApellidoPaterno());
        this.apellidoMaterno2.setText(pac.getApellidoMaterno());
        this.prevision2.setText(pac.getPrevision());
        this.telefono3.getTelefono().setText(pac.getTelefono());
        this.fechaNacimiento2.setText(pac.getFechaNac());
        this.profesion2.setText(pac.getProfesion());
        //Bloquear campos que no se pueden Modificar
        this.rut3.getRut().setEditable(false);
        this.nombres2.setEditable(false);
        this.apellidoPaterno2.setEditable(false);
        this.apellidoMaterno2.setEditable(false);
        this.prevision2.setEditable(false);
        this.telefono3.getTelefono().setEditable(false);
        this.fechaNacimiento2.setEditable(false);
        this.profesion2.setEditable(false);
        //bloquear los campos de evolucion
        this.desdeEvo2.setEnabled(false);
        this.hastaEvo2.setEnabled(false);
        this.tablaAsistencia2.setEnabled(false);
        this.agregarEvolucion2.setEnabled(false);
        this.modificarvolucion2.setEnabled(false);
        this.verEvolucion.setEnabled(false);

    }

    void llenarFormularioPodoModificar(service.FichaPodologa fichaP) {
        //buscar información del paciente seleccionado
        service.Paciente pac = new service.Paciente();
        pac = buscarPaciente(fichaP.getPaciente());

        //llena los datos personales del paciente
        this.rut3.getRut().setText(fichaP.getPaciente());
        this.nombres2.setText(pac.getNombres());
        this.apellidoPaterno2.setText(pac.getApellidoPaterno());
        this.apellidoMaterno2.setText(pac.getApellidoMaterno());
        this.prevision2.setText(pac.getPrevision());
        this.fechaNacimiento2.setText(pac.getFechaNac());
        this.telefono3.getTelefono().setText(pac.getTelefono());
        this.profesion2.setText(pac.getProfesion());
        //los Datos del Paciente no se pueden modificar en ninguna acción del módulo de ficha clínica
        this.rut3.getRut().setEditable(false);
        this.nombres2.setEditable(false);
        this.apellidoPaterno2.setEditable(false);
        this.apellidoMaterno2.setEditable(false);
        this.prevision2.setEditable(false);
        this.fechaNacimiento2.setEditable(false);
        this.telefono3.getTelefono().setEditable(false);
        this.profesion2.setEditable(false);
        //llena los datos clinicos del paciente
        String calza =fichaP.getNumeroCalzado();
        char[] c1=calza.toCharArray();
        this.cal.setValue(Integer.parseInt(((Character)c1[0]).toString()));
        this.cal2.setValue(Integer.parseInt(((Character)c1[1]).toString()));
        
        this.medicamentos.setText(fichaP.getMedicamentos());
        if (fichaP.isCalzadoAdecuado() == true) {
            this.jRadioButton10.setSelected(true);
            this.jRadioButton9.setSelected(false);
        } else {
            this.jRadioButton9.setSelected(true);
            this.jRadioButton10.setSelected(false);
        }
        if (fichaP.isProblemaOrtopedico() == true) {
            this.jRadioButton6.setSelected(true);
            this.jRadioButton5.setSelected(false);
        } else {
            this.jRadioButton5.setSelected(true);
            this.jRadioButton6.setSelected(false);
        }
        if (fichaP.isCaminaConAyuda() == true) {
            this.jRadioButton2.setSelected(true);
            this.jRadioButton1.setSelected(false);
        } else {
            this.jRadioButton1.setSelected(true);
            this.jRadioButton2.setSelected(false);
        }
        if (fichaP.isDiabetesMellitus() == true) {
            this.jRadioButton4.setSelected(true);
            this.jRadioButton3.setSelected(false);
        } else {
            this.jRadioButton3.setSelected(true);
            this.jRadioButton4.setSelected(false);
        }
        if (fichaP.isHta() == true) {
            this.jRadioButton8.setSelected(true);
            this.jRadioButton7.setSelected(false);
        } else {
            this.jRadioButton7.setSelected(true);
            this.jRadioButton8.setSelected(false);
        }
        if (fichaP.isUlceracionPrevia() == true) {
            this.jRadioButton11.setSelected(true);
            this.jRadioButton12.setSelected(false);
        } else {
            this.jRadioButton12.setSelected(true);
            this.jRadioButton11.setSelected(false);
        }
        if (fichaP.isAmputacionPrevia() == true) {
            this.jRadioButton13.setSelected(true);
            this.jRadioButton14.setSelected(false);
        } else {
            this.jRadioButton14.setSelected(true);
            this.jRadioButton13.setSelected(false);
        }
        if (fichaP.isAlergias() == true) {
            this.jRadioButton15.setSelected(true);
            this.jRadioButton20.setSelected(false);
        } else {
            this.jRadioButton20.setSelected(true);
            this.jRadioButton15.setSelected(false);
        }
        if (fichaP.isVarices() == true) {
            this.jRadioButton16.setSelected(true);
            this.jRadioButton19.setSelected(false);
        } else {
            this.jRadioButton19.setSelected(true);
            this.jRadioButton16.setSelected(false);
        }
        if (fichaP.isEnfermedadesCronicas() == true) {
            this.jRadioButton17.setSelected(true);
            this.jRadioButton18.setSelected(false);
        } else {
            this.jRadioButton18.setSelected(true);
            this.jRadioButton17.setSelected(false);
        }
    }

    public service.Paciente buscarPaciente(String paciente) {
        service.PacienteWS_Service service = new service.PacienteWS_Service();
        service.PacienteWS port = service.getPacienteWSPort();

        java.util.List<service.Paciente> pacientes = port.listarPacientes();
        //buscar paciente por el rut
        for (int i = 0; i < pacientes.size(); i++) {
            if (pacientes.get(i).getRut().equals(paciente)) {
                return pacientes.get(i);
            }
        }
        return null;
    }

    public void habilitarCamposFormularioPodo(boolean habilitar) {
        this.jRadioButton1.setEnabled(habilitar);
        this.jRadioButton2.setEnabled(habilitar);
        this.jRadioButton3.setEnabled(habilitar);
        this.jRadioButton4.setEnabled(habilitar);
        this.jRadioButton5.setEnabled(habilitar);
        this.jRadioButton6.setEnabled(habilitar);
        this.jRadioButton7.setEnabled(habilitar);
        this.jRadioButton8.setEnabled(habilitar);
        this.jRadioButton9.setEnabled(habilitar);
        this.jRadioButton10.setEnabled(habilitar);
        this.jRadioButton11.setEnabled(habilitar);
        this.jRadioButton12.setEnabled(habilitar);
        this.jRadioButton13.setEnabled(habilitar);
        this.jRadioButton14.setEnabled(habilitar);
        this.jRadioButton15.setEnabled(habilitar);
        this.jRadioButton16.setEnabled(habilitar);
        this.jRadioButton17.setEnabled(habilitar);
        this.jRadioButton18.setEnabled(habilitar);
        this.jRadioButton19.setEnabled(habilitar);
        this.jRadioButton20.setEnabled(habilitar);
        this.cal.setEnabled(habilitar);
        this.cal2.setEnabled(habilitar);
        this.medicamentos.setEditable(habilitar);
        this.desdeEvo2.setEnabled(habilitar);
        this.hastaEvo2.setEnabled(habilitar);
        this.tablaAsistencia2.setEnabled(habilitar);
        this.agregarEvolucion2.setEnabled(habilitar);
        this.modificarvolucion2.setEnabled(habilitar);
        this.verEvolucion.setEnabled(habilitar);

    }
    private boolean estaDuplicada(String paciente, String profesional) {
        java.util.List<service.FichaPodologa> fichas = listarFichas();
        for (int i = 0; i < fichas.size(); i++) {
            if (fichas.get(i).getPaciente().equals(paciente) && fichas.get(i).getProfesional().equals(profesional)) {
                return true;
            }
        }
        return false;
    }

    private static java.util.List<service.FichaPodologa> listarFichas() {
        service.FichaPodologaWSService service = new service.FichaPodologaWSService();
        service.FichaPodologaWS port = service.getFichaPodologaWSPort();
        return port.listarFichasPodo();
    }

    private void valoresBooleanosFicha() {
        if (this.jRadioButton10.isSelected() == true) {
            calzadoAdecuado = true;
        } else {
            calzadoAdecuado = false;
        }
        if (this.jRadioButton6.isSelected() == true) {
            problemaOrto = true;
        } else {
            problemaOrto = false;
        }
        if (this.jRadioButton2.isSelected() == true) {
            caminaAyuda = true;
        } else {
            caminaAyuda = false;
        }
        if (this.jRadioButton4.isSelected() == true) {
            diabetesM = true;
        } else {
            diabetesM = false;
        }
        if (this.jRadioButton8.isSelected() == true) {
            hta = true;
        } else {
            hta = false;
        }
        if (this.jRadioButton11.isSelected() == true) {
            ulceracion = true;
        } else {
            ulceracion = false;
        }
        if (this.jRadioButton13.isSelected() == true) {
            amputacion = true;
        } else {
            amputacion = false;
        }
        if (this.jRadioButton15.isSelected() == true) {
            alergias = true;
        } else {
            alergias = false;
        }
        if (this.jRadioButton16.isSelected() == true) {
            varices = true;
        } else {
            varices = false;
        }
        if (this.jRadioButton17.isSelected() == true) {
            enfermedadesCro = true;
        } else {
            enfermedadesCro = false;
        }
    }

    public service.FichaPodologa buscarFicha(Long fichaKine) {
        service.FichaPodologaWSService service = new service.FichaPodologaWSService();
        service.FichaPodologaWS port = service.getFichaPodologaWSPort();

        java.util.List<service.FichaPodologa> fichasPodo = port.listarFichasPodo();
        //buscar paciente por el rut
        for (int i = 0; i < fichasPodo.size(); i++) {
            if (fichasPodo.get(i).getId().equals(fichaKine)) {
                return fichasPodo.get(i);
            }
        }
        return null;
    }

    public String eligeDireccionArchivo() {
        String dirArchivo = "";
        JFileChooser jFileChooser1 = new JFileChooser();
        jFileChooser1.setDialogTitle("Guardar archivo:");
        jFileChooser1.setVisible(true);

        int r = jFileChooser1.showSaveDialog(null);
        if (r == JFileChooser.APPROVE_OPTION) {
            File file = jFileChooser1.getSelectedFile();
            dirArchivo = String.valueOf(file);
        }
        dirArchivo = dirArchivo.replace('\\', '/') + ".pdf";
        return dirArchivo;

    }

    private void imprimirFichaClinica(service.FichaPodologa ficha) throws FileNotFoundException, DocumentException {
        service.Paciente paciente = buscarPaciente(ficha.getPaciente());
        Document documento = new Document();
        String dirArchivo = eligeDireccionArchivo();

        FileOutputStream ficheroPdf = new FileOutputStream(dirArchivo);// Se crea el OutputStream para el fichero donde queremos dejar el pdf.
        // Se asocia el documento al OutputStream y se indica que el espaciado entre
        // lineas sera de 20. Esta llamada debe hacerse antes de abrir el documento
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
        documento.open();// Se abre el documento.

        Paragraph titulo = new Paragraph("FICHA CLINICA PODOLOGÍA");
        titulo.setAlignment(Element.ALIGN_CENTER);
        titulo.setSpacingAfter(20);
        documento.add(titulo);

        Paragraph datosPersonales = new Paragraph("Datos Personales");
        datosPersonales.setAlignment(Element.ALIGN_LEFT);
        datosPersonales.setSpacingAfter(20);
        documento.add(datosPersonales);

        PdfPTable table = new PdfPTable(2);
        table.addCell("Rut: ");
        table.addCell(paciente.getRut());
        table.addCell("Nombres: ");
        table.addCell(paciente.getNombres());
        table.addCell("Apellido Paterno:");
        table.addCell(paciente.getApellidoPaterno());
        table.addCell("Apellido Materno: ");
        table.addCell(paciente.getApellidoMaterno());
        table.addCell("Previsión: ");
        table.addCell(paciente.getPrevision());
        table.addCell("Fecha de Nacimiento: ");
        table.addCell(paciente.getFechaNac());
        table.addCell("Telefono: ");
        table.addCell(paciente.getTelefono());
        table.addCell("Profesión: ");
        table.addCell(paciente.getProfesion());
        documento.add(table);

        Paragraph datosClinicos = new Paragraph("Datos Clínicos");
        datosClinicos.setAlignment(Element.ALIGN_LEFT);
        datosClinicos.setSpacingAfter(20);
        documento.add(datosClinicos);

        PdfPTable tabla = new PdfPTable(2);
        tabla.addCell("Calzado Adecuado: ");
        if (ficha.isCalzadoAdecuado() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Problemas Ortopédicos: ");
        if (ficha.isProblemaOrtopedico() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Camina con Ayuda: ");
        if (ficha.isCaminaConAyuda() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Diabetes Mellitus: ");
        if (ficha.isDiabetesMellitus() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("H.T.A: ");
        if (ficha.isHta() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Número de Calzado: ");
        tabla.addCell(ficha.getNumeroCalzado());
        tabla.addCell("Ulceración Previa: ");
        if (ficha.isUlceracionPrevia() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Amputación Previa: ");
        if (ficha.isUlceracionPrevia() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Alergias: ");
        if (ficha.isAlergias() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Varices: ");
        if (ficha.isVarices() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Enfermedades Crónicas: ");
        if (ficha.isEnfermedadesCronicas() == true) {
            tabla.addCell("Si");
        } else {
            tabla.addCell("No");
        }
        tabla.addCell("Medicamentos: ");
        tabla.addCell(ficha.getMedicamentos());
        documento.add(tabla);

        documento.close();
        abrirArchivo(dirArchivo);
    }

    public void abrirArchivo(String direccion) {
        //Abre el documento pdf
        try {
            File file = new File(direccion);
            Desktop.getDesktop().open(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void agregarDatoTablaEvolucion(int sesion, String fechaEvolucion, String comentario) {
        int fila = this.tablaAsistencia2.getRowCount();
        DefaultTableModel modelo = (DefaultTableModel) this.tablaAsistencia2.getModel();
        modelo.addRow(new String[3]);

        //coloca los datos de la ficha recientemente agregada
        for (int col = 0; col < this.tablaAsistencia2.getColumnCount(); col++) {
            this.tablaAsistencia2.setValueAt(sesion, fila, 0);
            this.tablaAsistencia2.setValueAt(fechaEvolucion, fila, 1);
            this.tablaAsistencia2.setValueAt(comentario, fila, 2);
        }
    }

    public void llenardatosEvoluciones(Long id) {
        //listar Evoluciones y agregarlas a la Tabla
        service.EvolucionWSService service = new service.EvolucionWSService();
        service.EvolucionWS port = service.getEvolucionWSPort();
        //Obtiene las fichas clinicas almacenadas en la base de datos
        java.util.List<service.Evolucion> evoluciones = port.listarEvoluciones();
        for (int i = 0; i < evoluciones.size(); i++) {
            if (evoluciones.get(i).isActivo() == true && evoluciones.get(i).getFichaClinica().equals(id)) {

                int fila = this.tablaAsistencia2.getRowCount();
                DefaultTableModel modelo = (DefaultTableModel) this.tablaAsistencia2.getModel();
                modelo.addRow(new String[3]);

                for (int col = 0; col < this.tablaAsistencia2.getColumnCount(); col++) {
                    this.tablaAsistencia2.setValueAt(evoluciones.get(i).getSesion(), fila, 0);
                    this.tablaAsistencia2.setValueAt(evoluciones.get(i).getFecha(), fila, 1);
                    this.tablaAsistencia2.setValueAt(evoluciones.get(i).getComentario(), fila, 2);
                }
            }
        }
    }

    public void limpiarTablaEvoluciones() {
        DefaultTableModel modelo = (DefaultTableModel) tablaAsistencia2.getModel();
        int filas = tablaAsistencia2.getRowCount();
        for (int i = 0; filas > i; i++) {
            modelo.removeRow(0);
        }
    }

    public void cambiarMensajeria(String eti) {
        p.etiquetaMensajeria.setText(eti);
    }

    public void modificarDatoTabla(int s, String fecha, String comentario) {
        int fila = this.tablaAsistencia2.getSelectedRow();
        this.tablaAsistencia2.setValueAt(s, fila, 0);
        this.tablaAsistencia2.setValueAt(fecha, fila, 1);
        this.tablaAsistencia2.setValueAt(comentario, fila, 2);
    }

    private boolean llenoDatosObligatorios() {

        if(this.cal.getValue()==null||this.cal2.getValue()==null || this.medicamentos.getText().equals("")){

            return false;
        }
        return true;
    }

    private void actualizarTablaFiltro() {
        this.limpiarTablaEvoluciones();
        //listar Evoluciones y agregarlas a la Tabla
        service.EvolucionWSService service = new service.EvolucionWSService();
        service.EvolucionWS port = service.getEvolucionWSPort();
        //Obtiene las fichas clinicas almacenadas en la base de datos
        java.util.List<service.Evolucion> evoluciones = port.listarEvoluciones();

        for (int i = 0; i < evoluciones.size(); i++) {
            Date d = this.stringToDate(evoluciones.get(i).getFecha());
            if (evoluciones.get(i).isActivo() == true && evoluciones.get(i).getFichaClinica().equals(id)) {
                if (this.desdeEvo2.getDate().before(d) && this.hastaEvo2.getDate().after(d) || this.esMismoDia(this.desdeEvo2.getDate(), d)
                        || this.esMismoDia(this.hastaEvo2.getDate(), d)) {

                    int fila = this.tablaAsistencia2.getRowCount();
                    DefaultTableModel modelo = (DefaultTableModel) this.tablaAsistencia2.getModel();
                    modelo.addRow(new String[3]);
                    for (int col = 0; col < this.tablaAsistencia2.getColumnCount(); col++) {
                        this.tablaAsistencia2.setValueAt(evoluciones.get(i).getSesion(), fila, 0);
                        this.tablaAsistencia2.setValueAt(evoluciones.get(i).getFecha(), fila, 1);
                        this.tablaAsistencia2.setValueAt(evoluciones.get(i).getComentario(), fila, 2);
                    }
                }
            }
        }
    }

    private static boolean esMismoDia(Date fecha1, Date fecha2) {
        if (fecha1 == null || fecha2 == null) {
            throw new IllegalArgumentException("Las fechas no pueden ser null");
        }
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(fecha1);
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(fecha2);
        return isSameDay(cal1, cal2);
    }

    private static boolean isSameDay(Calendar cal1, Calendar cal2) {
        if (cal1 == null || cal2 == null) {
            throw new IllegalArgumentException("Las fechas no pueden ser null");
        }
        return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
    }

    public Date stringToDate(String strFecha) {
        SimpleDateFormat formatoDelTexto = new SimpleDateFormat("dd-MM-yyyy");
        Date fecha = null;
        try {
            fecha = formatoDelTexto.parse(strFecha);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        System.out.println(formatoDelTexto.format(fecha));
        return fecha;

    }

    private static Long registrar(service.Usuario usuario, java.lang.String modulo, java.lang.String accion, java.lang.String valorAnterior, java.lang.String valorNuevo) {
        service.BitacoraWSService service = new service.BitacoraWSService();
        service.BitacoraWS port = service.getBitacoraWSPort();
        return port.registrar(usuario, modulo, accion, valorAnterior, valorNuevo);
    }

   public void ocultarAsteriscosFormulario(boolean ocultar){
        if(ocultar==true){
            this.jLabel4.setText("");
            this.jLabel5.setText("");
            this.jLabel6.setText("");
            this.mensajeriaFormulario.setText("");
        }else{
            this.jLabel4.setText("*");
            this.jLabel5.setText("*");
            this.jLabel6.setText("*Datos obligatorios");
            this.mensajeriaFormulario.setText("Área de mensajería");
        }
    }
   
    void habilitarCamposEvolucion(boolean b) {
        this.desdeEvo2.setEnabled(b);
        this.hastaEvo2.setEnabled(b);
        this.tablaAsistencia2.setEnabled(b);
        this.verEvolucion.setEnabled(b);
    }
}
